package com.bzkj.web.controller.basic;

import com.bzkj.basicinfo.domain.basic.WarehouseType;
import com.bzkj.basicinfo.service.basic.WarehouseTypeService;
import com.bzkj.common.annotation.Log;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 仓库类型Controller
 * 
 * @author bzkj
 */
@Api(tags = "仓库类型管理")
@RestController
@RequestMapping("/basic/warehouseType")
public class WarehouseTypeController extends BaseController
{
    @Autowired
    private WarehouseTypeService warehouseTypeService;

    /**
     * 查询仓库类型列表
     */
    @PreAuthorize("@ss.hasPermi('basic:warehouseType:list')")
    @ApiOperation("查询仓库类型列表")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseType warehouseType)
    {
        startPage();
        List<WarehouseType> list = warehouseTypeService.selectWarehouseTypeList(warehouseType);
        return getDataTable(list);
    }

    /**
     * 获取所有启用的仓库类型（用于下拉选择）
     */
    @ApiOperation("获取所有启用的仓库类型")
    @GetMapping("/all")
    public AjaxResult getAllTypes()
    {
        List<WarehouseType> list = warehouseTypeService.selectAllWarehouseTypes();
        return AjaxResult.success(list);
    }

    /**
     * 根据ID获取仓库类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:warehouseType:query')")
    @ApiOperation("获取仓库类型详细信息")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(warehouseTypeService.selectWarehouseTypeById(id));
    }

    /**
     * 新增仓库类型
     */
    @PreAuthorize("@ss.hasPermi('basic:warehouseType:add')")
    @ApiOperation("新增仓库类型")
    @Log(title = "仓库类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseType warehouseType)
    {
        return toAjax(warehouseTypeService.insertWarehouseType(warehouseType));
    }

    /**
     * 修改仓库类型
     */
    @PreAuthorize("@ss.hasPermi('basic:warehouseType:edit')")
    @ApiOperation("修改仓库类型")
    @Log(title = "仓库类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseType warehouseType)
    {
        return toAjax(warehouseTypeService.updateWarehouseType(warehouseType));
    }

    /**
     * 删除仓库类型
     */
    @PreAuthorize("@ss.hasPermi('basic:warehouseType:remove')")
    @ApiOperation("删除仓库类型")
    @Log(title = "仓库类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(warehouseTypeService.deleteWarehouseTypeById(id));
    }

    /**
     * 修改仓库类型状态
     */
    @PreAuthorize("@ss.hasPermi('basic:warehouseType:edit')")
    @ApiOperation("修改仓库类型状态")
    @Log(title = "仓库类型", businessType = BusinessType.UPDATE)
    @PutMapping("/status")
    public AjaxResult updateStatus(@RequestBody WarehouseType warehouseType)
    {
        return toAjax(warehouseTypeService.updateWarehouseTypeStatus(
            warehouseType.getId(), 
            warehouseType.getStatus()
        ));
    }
}
